<template>
	<a-input-search :placeholder="placeholder" v-model="childModel" :disabled="disabled" enter-button read-only @search="search" />
</template>

<script>
export default {
	name: 'zInputSearch',
	model: {},
	props: {
		// 当前组件绑定值
		model: {
			type: [String, Number],
			require: true,
		},
		// 输入框默认值
		placeholder: {
			type: String,
			default: '',
		},
		// 是否禁用
		disabled: {
			type: Boolean,
			default() {
				return false;
			},
		},
		// 点击查询按钮触发
		search: {
			type: Function,
			default() {},
		},
	},
	data() {
		return {
			childModel: this.model,
		};
	},
	watch: {
		childModel(val) {
			// console.log('input', val);
			this.$emit('update:model', val);
			// 重置操作时不触发验证
			if (!(val === null)) {
				this.handleChange();
			}
		},

		model(val) {
			this.childModel = val;
			this.$emit('update:model', val);
		},
	},
	methods: {
		emitModel(val) {
			this.$emit('update:model', val);
		},
		handleChange() {
			this.$parent.$parent.$parent.$parent.onFieldChange();
		},
	},
};
</script>

<style></style>
